/*
 * @Author: your name
 * @Date: 2024-05-27 
 * @LastEditTime: 2024-06-06 
 * @LastEditors: 杨世豪
 * @Description: In User Settings Edit
 * @FilePath: \src\api\index.js
 */
import 'ol/ol.css'

import dmLayer from './layer'
import dmMap from './map'
//import dmMarker from './marker'
// import dmFormat from './format'
// import dmPolygon from './polygon'
// import dmPolyline from './polyline'
// import dmControl from './control'
// import dmInteraction from './interaction'

function Map(containerId, centerCoor, zoom, proj, minZoom, maxZoom) {
    this.map = dmMap.init(containerId, centerCoor, zoom, proj, minZoom, maxZoom);
    this.view = this.map.getView();
    this.layer = new dmLayer(this.map);
    // this.marker = new dmMarker(this.map);
    // this.format = new dmFormat(this.map);
    // this.polygon = new dmPolygon(this.map);
    // this.polyline = new dmPolyline(this.map);
    // this.control = new dmControl(this.map);
    // this.interaction = new dmInteraction(this.map);
}

/**
 * @description: 设置显示中心
 * @param {array} lonlat 中心点经纬度
 * @param {int} zoom 缩放级别 
 * @return {*}
 */
Map.prototype.panTo = function(lonlat, zoom) {
    if (zoom) {
        this.view.animate({
            zoom: zoom,
            center: lonlat,
            duration: 1000
        });
    } else {
        this.view.animate({
            center: lonlat,
            duration: 1000 //动画效果时间
        })
    }
};

Map.prototype.moveToExtent = function(extent) {
    this.map.getView().fit(extent, { duration: 800 });
}

export default Map